﻿using System;
using System.Collections.Generic;
using System.Text;
using OSGeo.MapGuide;
using System.Drawing;
using System.ComponentModel;

namespace MapViewer
{
    public delegate void CircleDigitizationCallback(double x, double y, double radius);
    public delegate void LineDigitizationCallback(double x1, double y1, double x2, double y2);
    public delegate void PointDigitizationCallback(double x, double y);
    public delegate void PolygonDigitizationCallback(double[,] coordinates);
    public delegate void LineStringDigitizationCallback(double[,] coordinates);
    public delegate void RectangleDigitizationCallback(double llx, double lly, double urx, double ury);

    public interface IMapViewer : IMapViewerComponent, INotifyPropertyChanged
    {
        void ClearSelection();

        void DigitizeCircle(CircleDigitizationCallback callback);
        void DigitizeLine(LineDigitizationCallback callback);
        void DigitizePoint(PointDigitizationCallback callback);
        void DigitizePolygon(PolygonDigitizationCallback callback);
        void DigitizeLineString(LineStringDigitizationCallback callback);
        void DigitizeRectangle(RectangleDigitizationCallback callback);

        MgdMap GetMap();
        MgdSelection GetSelection();
        MgCoordinateSystem CoordinateSystem { get; }

        MapActiveTool ActiveTool { get; set; }
        double ZoomInFactor { get; set; }
        double ZoomOutFactor { get; set; }
        bool FeatureTooltipsEnabled { get; set; }

        bool IsBusy { get; }

        MapDigitizationType DigitizingType { get; }

        void RefreshMap();
        event EventHandler MapRefreshed;

        void PanLeft(bool refresh);
        void PanUp(bool refresh);
        void PanRight(bool refresh);
        void PanDown(bool refresh);

        void InitialMapView();
        void ZoomToView(double x, double y, double scale, bool refresh);

        event EventHandler MapScaleChanged;
        event EventHandler SelectionChanged;
        event EventHandler ViewerInitialized;
        event EventHandler<MapPointEventArgs> MouseMapPositionChanged;

        void ZoomToExtents(double llx, double lly, double urx, double ury);
    }

    public class MapPointEventArgs : EventArgs 
    {
        public readonly double X;
        public readonly double Y;

        public MapPointEventArgs(double x, double y)
        {
            this.X = x; 
            this.Y = y;
        }
    }

    public enum MapDigitizationType
    {
        None,
        Point,
        Line,
        LineString,
        Rectangle,
        Polygon,
        Circle
    }

    public enum MapActiveTool
    {
        ZoomIn,
        ZoomOut,
        Pan,
        Select,
        None
    }

    public class PointEventArgs : EventArgs
    {
        public PointEventArgs(PointF p) { this.Point = p; }

        public PointF Point { get; private set; }
    }
}
